package com.laxcen.toydemo;

import android.os.Bundle;

import androidx.annotation.Nullable;

import site.gemus.openingstartanimation.NormalDrawStrategy;
import site.gemus.openingstartanimation.OpeningStartAnimation;
import util.BackgroundMusic;
import util.DefaultHandler;

public class SplashActivity extends BaseActivity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);

        startPlayBgSound();
        startOpeningStartAnimation();
        startFinishDelay();
    }

    private void startFinishDelay() {
        new DefaultHandler().postDelayed(new Runnable() {
            @Override
            public void run() {
                startActivity(ConnectActivity.class);
                finish();
            }
        }, 5000);
    }

    private void startPlayBgSound() {
        BackgroundMusic.instance(this).play(R.raw.splash_bg_sound, false);
    }

    private void startOpeningStartAnimation() {
        OpeningStartAnimation openingStartAnimation = new OpeningStartAnimation.Builder(this)
                .setDrawStategy(new NormalDrawStrategy())
                .create();
        openingStartAnimation.show(this);
    }

    @Override
    protected void onDestroy() {
//        BackgroundMusic.instance(this).stop();
        super.onDestroy();
    }
}
